perm filename DCOUNT.CH[UHF,DEK] blob
sn#841755 filedate 1987-06-18 generic text, type T, neo UTF8
% Change file for DDTONE.WEB, changes to yield the ordered dither method
@x
begin i←class_row[k]; j←class_col[k];
while j≤nn do
begin @<Decide the color of pixel |[i,j]| and the resulting |err|@>;
for l←start[k] to start[k+1]-1 do
begin u←i+del_i[l]; v←j+del_j[l];
buffer[u,v]←buffer[u,v]+err*alpha[l];
end;
@y
begin i←class_row[k]-3; j←class_col[k];
while j≤nn do
begin @<Decide the color of pixel |[i,j]| and the resulting |err|@>;
if k=63 then
begin sb←0.0; sd←0;
for si←-2 to 5 do for sj←j to j+7 do if sj≤nn then
begin sb←sb+buffer[si,sj]; sd←sd+darkness[si,sj];
end;
tot_err←tot_err+abs(sb-sd); incr(squares);
if abs(sb-sd)≥1.0 then incr(tot_bad1);
if abs(sb-sd)≥2.0 then incr(tot_bad2);
end;
@z
@x
@!alpha:array[0..256] of real; {constant of proportionality for diffusion}
@y
@!alpha:array[0..256] of real; {constant of proportionality for diffusion}
@!si,@!sj,@!sd:integer; {indices and accumulated darkness in square}
@!sb:real; {accumulated density in square}
@!tot_err:real; {sum of absolute discrepancies}
@!squares:integer; {number of data values accumulated in |tot_err|}
@!tot_bad1,tot_bad2:integer; {number of squares with large discrepancies}
@ @<Set init...@>=
tot_err←0.0; squares←-32; {32 at beginning are zero}
tot_bad1←0; tot_bad2←0;
@z
@x
err←buffer[i,j]; err_black←err-1.0;
if err_black+err>0 then
begin err←err_black; darkness[i,j]←black;
end
@y
if buffer[i,j]≥(k+0.5)/64.0 then darkness[i,j]←black
@z
@x
begin store(i,j); store(i-4,j+4); store(5-j,i); store(1-j,i-4);@/
store(4+j,1-i); store(j,5-i); store(5-i,5-j); store(1-i,1-j);
end;
@ @<Initialize the class number matrix@>=
k←0; store_eight(7,2); store_eight(8,3); store_eight(8,2); store_eight(8,1);@/
store_eight(1,4); store_eight(1,3); store_eight(1,2); store_eight(2,3);@/
@y
begin store(i,j); store(i+4,j+4); store(i,j+4); store(i+4,j);@/
store(i+2,j+2); store(i+6,j+6); store(i+2,j+6); store(i+6,j+2);
end;
procedure stero_eight(@!i,@!j:integer); {dual of the other}
begin store(i,j); store(i+4,j+4); store(i,j+4); store(i+4,j);@/
store(i+2,j+6); store(i+6,j+2); store(i+2,j+2); store(i+6,j+6);
end;
@ @<Initialize the class number matrix@>=
k←0; store_eight(1,1); stero_eight(1,3); store_eight(2,2); stero_eight(2,4);@/
store_eight(1,2); stero_eight(1,4); store_eight(2,1); stero_eight(2,3);@/
@z
@x
if hold[i,j] then class_row[k]←i-8;
@y
@z
@x
cleanup_and_terminate:
@y
write_ln(tty,tot_err:10:5,' errors in ',squares:1,' squares, ave=',tot_err/squares:10:5);
write_ln(tty,'Bad squares: ',tot_bad1:1,'≥1.0; ',tot_bad2:2,'≥2.0');
cleanup_and_terminate:
@z